﻿#$language = "Python"
#$interface = "1.0"

import sys, os

localPath = os.path.dirname(os.path.abspath(__file__))
commonPath = localPath + "\\common"
if commonPath not in sys.path:
    sys.path.insert(0, commonPath)

import common_crt

def main():
    crt.Screen.Synchronous = True

    if(crt.Session.Connected != True):
        return -1

    if common_crt.get_prompt(crt) != common_crt.PROMPT_LINUX_ROOT:
        common_crt.error_msg(crt, "This session is not root for Linux.")
        return -1

    screen = common_crt.Screen(crt, common_crt.PROMPT_LINUX_ROOT)
    rslt = screen.send("ls --color=no /mnt | grep 'OMU'\r")
    if not rslt:
        common_crt.error_msg(crt, "This session is not mcRNC.")
        retun -1
    filePath = crt.Dialog.FileOpenDialog(title="Please select a RNWPlan", filter="xml Files (*.xml)|*.xml||")
    if filePath == "":
        return 2
    elif(os.path.isfile(filePath) != True):
        common_crt.error_msg(crt, "RNWPlan not exist!\r\n" + filePath)
        return 1
    sftp = common_crt.Sftp(crt)
    sftp.upload(filePath, "/mnt/" + rslt + "/plan/RNWPLAND.XML")
    del sftp
    crt.Screen.Synchronous = False
    return 0

main()
